package com.example.wanted.controller;

import com.example.wanted.model.Question;
import com.example.wanted.model.User;
import com.example.wanted.service.QuestionService;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
public class QuestionController {
    final QuestionService questionService;
    @Autowired
    public QuestionController(QuestionService questionService) {
        this.questionService = questionService;
    }

    @PostMapping("question")
    public void saveQuestion(@RequestBody Question q, HttpServletResponse res, HttpServletRequest req) {
        System.out.println(q);
        questionService.save(q);
    }

    @GetMapping("get_question_by_question_id")
    public Question findByQuestionID(@RequestParam Long question_id,HttpServletResponse res, HttpServletRequest req){
        System.out.println(question_id);
        return questionService.findByQuestionID(question_id);
    }

    @GetMapping("get_questions")
    public List<Question> getQuestions(HttpServletResponse res, HttpServletRequest req){
        System.out.println(questionService.getQuestions());
        return questionService.getQuestions();
    }

    @GetMapping("question_sum")
    public Long findSumQuestion(HttpServletResponse res, HttpServletRequest req){
        System.out.println(questionService.findSumQuestion());
        return questionService.findSumQuestion();
    }
}
